package cn.xfdzx.android.apps.shop.activity;


import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Paint;
import android.graphics.Point;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.CycleInterpolator;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;
import com.youth.banner.listener.OnBannerListener;
import com.youth.banner.loader.ImageLoader;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;
import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.activity.login.OneLoginMainActivity;
import cn.xfdzx.android.apps.shop.adapter.CarCouponsLVAdapter;
import cn.xfdzx.android.apps.shop.adapter.CarManJianLVAdapter;
import cn.xfdzx.android.apps.shop.adapter.GoodsDetailsGVAdapter;
import cn.xfdzx.android.apps.shop.adapter.GoodsDetailsTuiJianAdapter;
import cn.xfdzx.android.apps.shop.adapter.ShopCarGoodsAdapter;
import cn.xfdzx.android.apps.shop.adapter.ShopTuiJianAdapter;
import cn.xfdzx.android.apps.shop.apps.Constants;
import cn.xfdzx.android.apps.shop.base.BaseMvpActivity;
import cn.xfdzx.android.apps.shop.bean.BaseObjectBean;
import cn.xfdzx.android.apps.shop.bean.CarCouponsBeen;
import cn.xfdzx.android.apps.shop.bean.CarManJianBeen;
import cn.xfdzx.android.apps.shop.bean.ConfirmGoodBeen;
import cn.xfdzx.android.apps.shop.bean.MoreGoodsBean;
import cn.xfdzx.android.apps.shop.bean.ShopCarListBeen;
import cn.xfdzx.android.apps.shop.bean.ShopGoodListBeen;
import cn.xfdzx.android.apps.shop.bean.ShopRemakeListRetailBean;
import cn.xfdzx.android.apps.shop.bean.StoreInfoBeen;
import cn.xfdzx.android.apps.shop.bean.XFDGoodsDetailsBeen;
import cn.xfdzx.android.apps.shop.contract.ItemClickListener;
import cn.xfdzx.android.apps.shop.contract.ShopRetailContract;
import cn.xfdzx.android.apps.shop.presenter.ShopRetailPresenter;
import cn.xfdzx.android.apps.shop.util.EmptyUtil;
import cn.xfdzx.android.apps.shop.util.ItemOffsetDecoration;
import cn.xfdzx.android.apps.shop.util.ProgressDialog;
import cn.xfdzx.android.apps.shop.util.ShopCarPopupWindow;
import cn.xfdzx.android.apps.shop.util.Utils;
import cn.xfdzx.android.apps.shop.util.UtilsData;
import cn.xfdzx.android.apps.shop.video.VideoActivity;
import cn.xfdzx.android.apps.shop.view.MaxHeightRecyclerView;
import cn.xfdzx.android.apps.shop.view.MyGridView;
import cn.xfdzx.android.apps.shop.view.ShoppingCartAnimationView;
import cn.xfdzx.android.apps.shop.view.SonicView;

import static cn.xfdzx.android.apps.shop.apps.Constants.APP_TOKEN;
import static cn.xfdzx.android.apps.shop.apps.Constants.SHOPID_69_NO;

/**
 * 零售商品详情页面
 */
public class GoodsDetailsActivity extends BaseMvpActivity<ShopRetailPresenter> implements ShopRetailContract.View {

    @BindView(R.id.banner_details)
    Banner banner;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_goods_old_price)
    TextView tvGoodsOldPrice;
    @BindView(R.id.gv_goods_juan)
    MyGridView gvGoodsJuan;
    @BindView(R.id.rv_goods)
    RecyclerView rvGoods;
    @BindView(R.id.tv_to_settle_accounts)
    TextView tvToSettleAccounts;
    @BindView(R.id.ll_coupon_redemption)
    LinearLayout llCouponRedemption;//领券
    @BindView(R.id.tv_add_car)
    TextView tvAddCar;
    @BindView(R.id.tv_goods_add)
    TextView tvGoodsAdd;
    @BindView(R.id.tv_goods_num)
    TextView tvGoodsNum;
    @BindView(R.id.tv_total_goods_num)
    TextView tvTotalGoodsNum;
    @BindView(R.id.tv_goods_minus)
    TextView tvGoodsMinus;
    @BindView(R.id.iv_shop_car)
    ImageView ivShopCar;
    @BindView(R.id.rl_shop_car)
    RelativeLayout rlShopCar;
    @BindView(R.id.view_shop_car_bg)
    View viewShopCarBg;
    @BindView(R.id.tv_shop_car_price)
    TextView tvShopCarPrice;
    @BindView(R.id.tv_goods_name)
    TextView tvGoodsName;
    @BindView(R.id.tv_month_sale)
    TextView tvMonthSale;
    @BindView(R.id.tv_goods_price)
    TextView tvGoodsPrice;
    @BindView(R.id.max_height_rv)
    MaxHeightRecyclerView maxHeightRv;
    @BindView(R.id.ll_car)
    LinearLayout llCar;
    @BindView(R.id.view_bg_black)
    View viewBgBlack;
    @BindView(R.id.tv_car_total_num)
    TextView tvCarTotalNum;
    @BindView(R.id.tv_clear_car)
    TextView tvClearCar;
    @BindView(R.id.tv_content)
    TextView tvContent;
     @BindView(R.id.tv_jian)
    TextView tvJian;
    @BindView(R.id.sonic_view)
    SonicView sonicView;
    @BindView(R.id.rl_video_zhibo)
    RelativeLayout rlVideoZhibo;

    private GoodsDetailsTuiJianAdapter goodsDetailsTuiJianAdapter;
    private ShopCarPopupWindow couponPopupWindow;
    private ShopCarPopupWindow carPopupWindow;
    private String good_id = "";
    private boolean is_from_car = false;

    private ArrayList<ShopCarListBeen.DataBean.ValidBean.GoodsBeanX> carList;

    private String total_price = "0";
    private int total_num = 0;
    private String shopID = "";
    private ShopCarGoodsAdapter shopCarGoodsAdapter;
    private int size;//当前商品数量
    private Context mContext;

    @Override
    public int getLayoutId() {
        return R.layout.activity_goods_details;
    }

    @Override
    public void initView() {
        mContext = GoodsDetailsActivity.this;
        mPresenter = new ShopRetailPresenter();
        mPresenter.attachView(this);
        good_id = getIntent().getStringExtra("good_id");

        carList = new ArrayList<>();


        initBanner();
        //领劵暂时关闭
//        initJuan();

        deafult_view();
        initCar();

        //商品详情
        mPresenter.initData(good_id);



    }

    /**
     *
     */
    private void initDate() {
        Map<String, Object> map = new HashMap<>();
        map.put("store_id", shopID);
        map.put("page", 1);
        map.put("limit", 6);
        mPresenter.getStoreGoodsList(map);
    }

    private void initCar() {
        maxHeightRv.setLayoutManager(new LinearLayoutManager(this));
        maxHeightRv.setItemAnimator(new DefaultItemAnimator());

        shopCarGoodsAdapter = new ShopCarGoodsAdapter(this, carList, mPresenter);
        maxHeightRv.setAdapter(shopCarGoodsAdapter);
    }

    private void deafult_view() {
        if (size == 0) {
            tvAddCar.setVisibility(View.VISIBLE);
            tvGoodsAdd.setVisibility(View.GONE);
            tvGoodsNum.setVisibility(View.GONE);
            tvGoodsMinus.setVisibility(View.GONE);
            tvGoodsNum.setText(size + "");
        } else {
            tvAddCar.setVisibility(View.GONE);
            tvGoodsAdd.setVisibility(View.VISIBLE);
            tvGoodsMinus.setVisibility(View.VISIBLE);
            tvGoodsNum.setVisibility(View.VISIBLE);
            tvGoodsNum.setText(size + "");

        }
        calculate();
    }



    private void initJuan() {
        gvGoodsJuan.setAdapter(new GoodsDetailsGVAdapter(this, new ArrayList<String>()));
    }

    private void initBanner() {
        banner.setImageLoader(new GlideImageLoader());
        banner.setBannerStyle(BannerConfig.NUM_INDICATOR);
        banner.setIndicatorGravity(BannerConfig.RIGHT);
        banner.setBannerAnimation(Transformer.Default);
        banner.isAutoPlay(true);
        banner.setDelayTime(3000);
        banner.setOnBannerListener(new OnBannerListener() {
            @Override
            public void OnBannerClick(int i) {

            }
        });


        tvGoodsOldPrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
    }

    private Dialog dialog;

    @OnClick({R.id.tv_clear_car, R.id.tv_goods_add, R.id.tv_goods_minus, R.id.tv_add_car, R.id.view_bg_black})
    public void Onclick(View view) {
        switch (view.getId()) {
            case R.id.tv_clear_car:
                if (Utils.isFastClick()) {
                    dialog = Utils.addDialog(this, R.layout.dialog, R.string.are_you_sure_you_want_to_clear_this_car, R.string.confirm, new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            String ids = "";
                            for (ShopCarListBeen.DataBean.ValidBean.GoodsBeanX goodsBeanX : carList) {
                                if (ids.isEmpty()) {
                                    ids = goodsBeanX.getId() + "";
                                } else {
                                    ids = ids + "," + goodsBeanX.getId();
                                }
                            }
                            mPresenter.removeGood(ids + "", "" + "", 0, true);
                            dialog.dismiss();
                        }
                    });
                    dialog.show();
                }
                break;
            case R.id.tv_goods_add:
                //加号 加入购物车
                if (EmptyUtil.isEmpty(APP_TOKEN)) {
                    Intent intent = new Intent(this, OneLoginMainActivity.class);
                    startActivity(intent);
                    return;
                }
                addAnimation(view);
                break;
            case R.id.tv_goods_minus:
                if (EmptyUtil.isEmpty(APP_TOKEN)) {
                    Intent intent = new Intent(this, OneLoginMainActivity.class);
                    startActivity(intent);
                    return;
                }
                if (size != 0) {
                    size--;
                }
                deafult_view();
                for (int k = 0; k < carList.size(); k++) {
                    if (good_id.equals(carList.get(k).getProduct_id() + "")) {
                        if (carList.get(k).getCart_num() == 1) {
                            //移除商品
                            mPresenter.removeGood(carList.get(k).getId() + "", good_id, k, false);
                        } else {
                            mPresenter.updateCarNum(carList.get(k).getId() + "", size, 0, k);//one_position无用
                        }
                        break;
                    }
                }

                break;
            case R.id.tv_add_car:
                //文字加入购物车
                if (EmptyUtil.isEmpty(APP_TOKEN)) {
                    Intent intent = new Intent(this, OneLoginMainActivity.class);
                    startActivity(intent);
                    return;
                }
                tvAddCar.setVisibility(View.GONE);
                tvGoodsAdd.setVisibility(View.VISIBLE);
                tvGoodsNum.setVisibility(View.VISIBLE);
                tvGoodsMinus.setVisibility(View.VISIBLE);
                addAnimation(view);
                break;
            case R.id.view_bg_black:
                // 关闭平移动画
                endTranslationAnimation();
                break;
        }
    }

    private void addAnimation(View view) {
        ShoppingCartAnimationView shoppingCartAnimationView = new ShoppingCartAnimationView(this);
        int postion[] = new int[2];
        view.getLocationInWindow(postion);
        shoppingCartAnimationView.setStartPosition(new Point(postion[0], postion[1]));
        ViewGroup rootView = (ViewGroup) getWindow().getDecorView();
        rootView.addView(shoppingCartAnimationView);
        int endPosition[] = new int[2];
        ivShopCar.getLocationInWindow(endPosition);
        shoppingCartAnimationView.setEndPosition(new Point(endPosition[0], endPosition[1]));
        shoppingCartAnimationView.startBeizerAnimation();
        rlShopCar.setAnimation(shakeAnimation(1));

        size++;
        if (size == 1) {
            mPresenter.addCar(0 + "", "", good_id + "", "1");
        } else {
            for (int k = 0; k < carList.size(); k++) {
                if (good_id.equals(carList.get(k).getProduct_id() + "")) {
                    mPresenter.updateCarNum(carList.get(k).getId() + "", size, 0, k);//one_position无用
                    break;
                }
            }
        }
        deafult_view();
    }

    /**
     * 计算
     */
    public void calculate() {
        int num = 0;
        double price = 0;
        for (ShopCarListBeen.DataBean.ValidBean.GoodsBeanX goodsInfoBean : carList) {
            num += goodsInfoBean.getCart_num();
            price += goodsInfoBean.getCart_num() * Double.parseDouble(goodsInfoBean.getProductInfo().getPrice());
        }
        total_price = format1(price);
        total_num = num;
        tvTotalGoodsNum.setText(total_num + "");
        tvShopCarPrice.setText("¥" + total_price);
        tvCarTotalNum.setText("购物车(共" + carList.size() + "件商品)");
        if (total_num == 0) {
            viewShopCarBg.setBackgroundResource(R.drawable.round_hui_bg);
            tvToSettleAccounts.setBackgroundResource(R.color.color_999999);
            tvShopCarPrice.setText(getResources().getText(R.string.unselected_goods));
            tvShopCarPrice.setTextSize(14);
            tvShopCarPrice.setTextColor(getResources().getColor(R.color.color_999999));
            tvTotalGoodsNum.setVisibility(View.INVISIBLE);
        } else {
            if (tvTotalGoodsNum.getVisibility() != View.VISIBLE) {
                tvTotalGoodsNum.setVisibility(View.VISIBLE);
                viewShopCarBg.setBackgroundResource(R.drawable.round_orange_bg);
                tvToSettleAccounts.setBackgroundResource(R.color.color_FB9129);

                tvShopCarPrice.setTextSize(17);
                tvShopCarPrice.setTextColor(getResources().getColor(R.color.color_F93331));
            }
        }
    }

    /**
     * 使用BigDecimal，保留小数点后两位
     */
    public String format1(double value) {

        BigDecimal bd = new BigDecimal(value);
        bd = bd.setScale(2, RoundingMode.HALF_UP);
        return bd.toString();
    }

    @Override
    public void showLoading() {

        if (!ProgressDialog.getInstance().materialDialog.isShowing()) {
            ProgressDialog.getInstance().show(this);
        }
    }

    @Override
    public void hideLoading() {

            ProgressDialog.getInstance().dismiss();

    }

    @Override
    public void onError(Throwable throwable) {

    }

    @Override
    public void onShopRetailSuccess(ShopGoodListBeen bean) {

    }

    @Override
    public void onShopStoreInfoSuccess(StoreInfoBeen bean) {

    }

    @Override
    public void onStart() {
        super.onStart();
        //开始轮播
        banner.startAutoPlay();

    }

    @Override
    public void onStop() {
        //结束轮播
        banner.stopAutoPlay();
        if (null != sonicView) {
            sonicView.stop();
        }
        super.onStop();
    }

    @Override
    public void onInitDataSuccess(XFDGoodsDetailsBeen bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            //设置图片网址或地址的集合
            banner.setImages(bean.getData().getStoreInfo().getSlider_image());
            //必须最后调用的方法，启动轮播图。
            banner.start();
            tvGoodsName.setText(bean.getData().getStoreInfo().getTitle() );
//            tvGoodsName.setText(bean.getData().getStoreInfo().getTitle()+(int)Double.parseDouble(bean.getData().getStoreInfo().getGoods_weight()) +"g");
            tvMonthSale.setText("月售" + bean.getData().getStoreInfo().getSales());


            if (Double.parseDouble(bean.getData().getStoreInfo().getDiscount_price()) == 0) {
                tvGoodsPrice.setText("¥" + bean.getData().getStoreInfo().getPrice() + "");
                tvGoodsOldPrice.setVisibility(View.GONE);
            } else {
                tvGoodsOldPrice.setVisibility(View.VISIBLE);
                tvGoodsPrice.setText("¥" + bean.getData().getStoreInfo().getDiscount_price() + "");
                tvGoodsOldPrice.setText("¥" + bean.getData().getStoreInfo().getPrice() + "");
            }
            shopID= bean.getData().getShopInfo().getId()+"";
            if (UtilsData.getPreference(mContext,"activity").getBoolean("is_69")&&!SHOPID_69_NO.contains(shopID)){
                tvContent.setText("满69任减1件商品");
                tvJian.setVisibility(View.VISIBLE);
            }
            //
            mPresenter.shopCarList(shopID, "0");
            //推荐商品
            initDate();
            if (bean.getData().getLive_id() == 0) {
                rlVideoZhibo.setVisibility(View.GONE);
            } else {
                rlVideoZhibo.setVisibility(View.VISIBLE);
                rlVideoZhibo.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(mContext, VideoActivity.class);
                        intent.putExtra("live_id", bean.getData().getLive_id() + "");
                        intent.putExtra("shop_type", "0");
                        mContext.startActivity(intent);
                    }
                });
            }

        } else {
            Toast.makeText(this, bean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    }

    //结算
    @Override
    public void onConfirmSuccess(ConfirmGoodBeen bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            Intent confirmOrder = new Intent(this, ConfirmOrderActivity.class);
            confirmOrder.putExtra("confirm", bean.getData());
            startActivity(confirmOrder);
        } else if (bean.getStatus() == 2000) {
            Toast.makeText(this, "此商铺已打烊", Toast.LENGTH_SHORT).show();
        } else {
            if (bean.getStatus() == Constants.LOGIN_CODE) {
                UtilsData.getPreference(this, "login").remove("head_url");
                UtilsData.getPreference(this, "login").remove("nickname");
                UtilsData.getPreference(this, "login").remove("is_store");
                UtilsData.getPreference(this, "login").remove("token");
                APP_TOKEN = "";
                Intent intent = new Intent(this, OneLoginMainActivity.class);
                startActivity(intent);
                return;
            }
            Toast.makeText(this, bean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    }

    //推荐商品
    @Override
    public void getStoreGoodsListSuccess(MoreGoodsBean bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
            linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
            ItemOffsetDecoration itemDecoration = new ItemOffsetDecoration(this, R.dimen.item_offset);
            rvGoods.setLayoutManager(linearLayoutManager);
            rvGoods.addItemDecoration(itemDecoration);
            ShopTuiJianAdapter ShopTuiJianAdapter = new ShopTuiJianAdapter(this, bean.getData());
            ShopTuiJianAdapter.setOnItemClickListener(new ItemClickListener() {
                @Override
                public void onItemClick(int position) {
                    Intent intent = new Intent(GoodsDetailsActivity.this, GoodsDetailsActivity.class);
                    intent.putExtra("good_id", bean.getData().get(position).getId() + "");

                    startActivity(intent);
                }
            });
            rvGoods.setAdapter(ShopTuiJianAdapter);

        } else {
            Toast.makeText(this, bean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void getGoodsCollectionSuccess(MoreGoodsBean bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            //detailsAdapter.setCollectionState(true);
            Toast.makeText(this, "收藏成功", Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(this, bean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void getGoodsCancleCollectionSuccess(MoreGoodsBean bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            //detailsAdapter.setCollectionState(false);
            Toast.makeText(this, "取消收藏", Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(this, bean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void getFocusShopSuccess(StoreInfoBeen bean) {

    }

    @Override
    public void onGetShopRemakeRetailSuccess(ShopRemakeListRetailBean bean) {

    }

    @Override
    public void onAddCarSuccess(ConfirmGoodBeen bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            mPresenter.shopCarList(shopID, "0");

            deafult_view();
        } else {
            for (ShopCarListBeen.DataBean.ValidBean.GoodsBeanX goodsBeanX : carList) {
                if (good_id.equals(goodsBeanX.getProduct_id() + "")) {
                    size = goodsBeanX.getCart_num();
                    tvGoodsNum.setText(goodsBeanX.getCart_num() + "");
                }
            }
            if (bean.getStatus() == Constants.LOGIN_CODE) {
                UtilsData.getPreference(this, "login").remove("head_url");
                UtilsData.getPreference(this, "login").remove("nickname");
                UtilsData.getPreference(this, "login").remove("is_store");
                UtilsData.getPreference(this, "login").remove("token");
                APP_TOKEN = "";
                Intent intent = new Intent(this, OneLoginMainActivity.class);
                startActivity(intent);
                return;
            }
            Toast.makeText(this, bean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onShopCarListSuccess(ShopCarListBeen bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            carList.clear();
            if (bean.getData().getValid().size() != 0) {
                carList.addAll(bean.getData().getValid().get(0).getGoods());
            }
            for (ShopCarListBeen.DataBean.ValidBean.GoodsBeanX goodsBeanX : carList) {
                if (good_id.equals(goodsBeanX.getProduct_id() + "")) {
                    size = goodsBeanX.getCart_num();
                    tvGoodsNum.setText(goodsBeanX.getCart_num() + "");
                }
            }
            deafult_view();
            shopCarGoodsAdapter.notifyDataSetChanged();
        } else {
//            Toast.makeText(this, bean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onUpdateCarNumSuccess(BaseObjectBean bean, int number, int one_position, int position) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {

            carList.get(position).setCart_num(number);
            calculate();
            shopCarGoodsAdapter.notifyDataSetChanged();

        } else {
            if (bean.getStatus() == Constants.LOGIN_CODE) {
                UtilsData.getPreference(this, "login").remove("head_url");
                UtilsData.getPreference(this, "login").remove("nickname");
                UtilsData.getPreference(this, "login").remove("is_store");
                UtilsData.getPreference(this, "login").remove("token");
                APP_TOKEN = "";
                Intent intent = new Intent(this, OneLoginMainActivity.class);
                startActivity(intent);
                return;
            }
            Toast.makeText(this, bean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onRemoveGoodSuccess(BaseObjectBean bean, String goodId, int position, boolean isAll) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            if (isAll) {
                mPresenter.shopCarList(shopID, "0");
            } else {
                if (good_id.equals(goodId)) {
                    size = 0;
                }
                deafult_view();
                carList.remove(position);
                calculate();
                shopCarGoodsAdapter.notifyDataSetChanged();
            }
        } else {
            if (bean.getStatus() == Constants.LOGIN_CODE) {
                UtilsData.getPreference(this, "login").remove("head_url");
                UtilsData.getPreference(this, "login").remove("nickname");
                UtilsData.getPreference(this, "login").remove("is_store");
                UtilsData.getPreference(this, "login").remove("token");
                APP_TOKEN = "";
                Intent intent = new Intent(this, OneLoginMainActivity.class);
                startActivity(intent);
                return;
            }
            Toast.makeText(this, bean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    protected boolean isUseFullScreenMode() {
        return true;
    }

    @OnClick({R.id.iv_back, R.id.ll_coupon_redemption, R.id.tv_to_settle_accounts, R.id.ll_led_securities, R.id.rl_shop_car})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;

            case R.id.ll_coupon_redemption:
                //领券关闭
//                if (couponPopupWindow != null) {
//
//                } else {
//                    couponPopupWindow = new ShopCarPopupWindow(this, R.layout.pw_coupon);
//                    couponPopupWindow.getRootView().findViewById(R.id.iv_back).setOnClickListener(new View.OnClickListener() {
//                        @Override
//                        public void onClick(View view) {
//                            couponPopupWindow.shareClose();
//
//                        }
//                    });
//                    ((ListView) couponPopupWindow.getRootView().findViewById(R.id.lv_juan)).setAdapter(new CarCouponsLVAdapter(this, new ArrayList<CarCouponsBeen>()));
//                }
//                couponPopupWindow.showPopupWindow();
                break;
            case R.id.tv_to_settle_accounts://去结算
                if (EmptyUtil.isEmpty(APP_TOKEN)) {
                    Intent intent = new Intent(this, OneLoginMainActivity.class);
                    startActivity(intent);
                    return;
                }
                if (carList.size() != 0) {
                    String ids = "";
                    for (ShopCarListBeen.DataBean.ValidBean.GoodsBeanX goodsBeanX : carList) {
                        if (ids.isEmpty()) {
                            ids = goodsBeanX.getId() + "";
                        } else {
                            ids = ids + "," + goodsBeanX.getId();
                        }
                    }
                    String user_curent_lng = UtilsData.getPreference(this, "coordinates").getString("coordinates_lng");
                    String user_curent_lat = UtilsData.getPreference(this, "coordinates").getString("coordinates_lat");
                    mPresenter.confirm(ids, user_curent_lng, user_curent_lat);
                } else {
                    Toast.makeText(this, "请选择商品", Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.rl_shop_car:
                if (total_num == 0) {
                    return;
                }
                if (llCar.getVisibility() == View.GONE) {
                    startTranslationAnimation();
                } else {
//                    关闭平移动画
                    endTranslationAnimation();
                }
                break;
            case R.id.ll_led_securities:
                if (carPopupWindow != null) {

                } else {
                    carPopupWindow = new ShopCarPopupWindow(this, R.layout.pw_shop_coupon);
                    carPopupWindow.getRootView().findViewById(R.id.iv_back).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            carPopupWindow.shareClose();
                            if (is_from_car) {
                                if (llCar.getVisibility() == View.GONE) {
                                    startTranslationAnimation();
                                    is_from_car = false;
                                }
                            }
                        }
                    });
                    ((ListView) carPopupWindow.getRootView().findViewById(R.id.lv_man_jian)).setAdapter(new CarManJianLVAdapter(this, new ArrayList<CarManJianBeen>()));
                    ((ListView) carPopupWindow.getRootView().findViewById(R.id.lv_juan)).setAdapter(new CarCouponsLVAdapter(this, new ArrayList<CarCouponsBeen>()));
                }
                if (llCar.getVisibility() != View.GONE) {
//                    关闭平移动画
                    endTranslationAnimation();
                    is_from_car = true;
                }
                carPopupWindow.showPopupWindow();
                break;
        }
    }


    class GlideImageLoader extends ImageLoader {
        @Override
        public void displayImage(Context context, Object path, ImageView imageView) {
            Glide.with(context).load(path).into(imageView);
        }

    }

    /*
     * 方法名：startTranslationAnimation()
     * 功    能：开启平移动画
     * 参    数：无
     * 返回值：无
     */
    private void startTranslationAnimation() {
//        TranslateAnimation startTranslateAnim = new TranslateAnimation(0, 0, -height, 0);
//        startTranslateAnim.setDuration(300);
//        llCar.startAnimation(startTranslateAnim);


        //设置动画，从自身位置的最下端向上滑动了自身的高度，持续时间为500ms
        final TranslateAnimation ctrlAnimation = new TranslateAnimation(
                TranslateAnimation.RELATIVE_TO_SELF, 0, TranslateAnimation.RELATIVE_TO_SELF, 0,
                TranslateAnimation.RELATIVE_TO_SELF, 1, TranslateAnimation.RELATIVE_TO_SELF, 0);
        ctrlAnimation.setDuration(300);     //设置动画的过渡时间
        llCar.postDelayed(new Runnable() {
            @Override
            public void run() {
                tvCarTotalNum.setText("购物车(共" + carList.size() + "件商品)");
                viewBgBlack.setVisibility(View.VISIBLE);
                llCar.setVisibility(View.VISIBLE);
                llCar.startAnimation(ctrlAnimation);
            }
        }, 300);

    }

    /*
     * 方法名：endTranslationAnimation()
     * 功    能：关闭平移动画
     * 参    数：无
     * 返回值：无
     */
    private void endTranslationAnimation() {
//        TranslateAnimation endTranslateAnim= new TranslateAnimation(0, 0, 0, -height);
//        endTranslateAnim.setDuration(300);
//        llCar.startAnimation(endTranslateAnim);

//        设置动画，从自身位置的最下端向上滑动了自身的高度，持续时间为500ms
        final TranslateAnimation ctrlAnimation = new TranslateAnimation(
                TranslateAnimation.RELATIVE_TO_SELF, 0, TranslateAnimation.RELATIVE_TO_SELF, 0,
                TranslateAnimation.RELATIVE_TO_SELF, 0, TranslateAnimation.RELATIVE_TO_SELF, 1);
        ctrlAnimation.setDuration(300);     //设置动画的过渡时间
        llCar.postDelayed(new Runnable() {
            @Override
            public void run() {
                viewBgBlack.setVisibility(View.GONE);
                llCar.setVisibility(View.GONE);
                llCar.startAnimation(ctrlAnimation);
            }
        }, 300);

    }


    @Override
    public void onBackPressed() {
        if (couponPopupWindow != null) {
            if (couponPopupWindow.isShowing()) {
                couponPopupWindow.shareClose();
                return;
            }
        }
        if (llCar.getVisibility() != View.GONE) {
//                    关闭平移动画
            endTranslationAnimation();
            return;
        }

        if (null != carPopupWindow) {
            if (carPopupWindow.isShowing()) {
                carPopupWindow.shareClose();
                return;
            }
        }
        super.onBackPressed();
    }

    @Override
    protected void onDestroy() {
        if (couponPopupWindow != null) {
            if (couponPopupWindow.isShowing()) {
                couponPopupWindow.dismiss();
            }
            couponPopupWindow = null;
        }
        if (carPopupWindow != null) {
            if (carPopupWindow.isShowing()) {
                carPopupWindow.dismiss();
            }
            carPopupWindow = null;
        }
        super.onDestroy();
    }

    public Animation shakeAnimation(int CycleTimes) {
        Animation animation = new ScaleAnimation(1.0f, 1.2f, 1.0f, 1.2f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
//        Animation translateAnimation = new TranslateAnimation(10, 10, 10, 10);
//        translateAnimation.setInterpolator(new CycleInterpolator(CycleTimes));
//        translateAnimation.setDuration(1000);
        animation.setInterpolator(new CycleInterpolator(CycleTimes));
        animation.setDuration(800);
        return animation;
    }

}
